<template>
  <div class="allbox">
    <div class="top">
      <h1>世界名茶</h1>
    </div>
    <div class="Advertisement"></div>
    <div class="flag">
      <div
        v-for="(tea, index) in teas"
        :key="index"
        :class="['tea', { active: activeTea === tea }]"
        @click="selectTea(tea)"
        @mouseover="hoverTea = tea"
        @mouseleave="hoverTea = null"
        :style="teaStyles(tea)"
      >
        {{ tea }}
      </div>
    </div>
    <div class="center"></div>
    <div class="center2"></div>
    <div class="foot">
      <div class="fleft" @click="jumpFirst">首页</div>
      <div class="fcenter" @click="jumpFriend">好友</div>
      <div class="fcenter2" @click="jumpActive">活动</div>
      <div class="fright" @click="jumpMyself">个人中心</div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const activeTea = ref(null); // 当前选中的茶类
const hoverTea = ref(null); // 当前鼠标悬停的茶类

const teas = [
  '绿茶',
  '白茶',
  '黄茶',
  '青茶',
  '红茶',
  '黑茶',
  '再加工茶类',
];

const teaColors = {
  '绿茶': '#008000', // 绿色
  '白茶': '#FFFFFF', // 白色
  '黄茶': '#FFFF00', // 黄色
  '青茶': '#00FF00', // 青色
  '红茶': '#FF0000', // 红色
  '黑茶': '#000000', // 黑色
  '再加工茶类': '#808080' // 灰色
};

function selectTea(tea) {
  activeTea.value = tea; // 更新当前选中的茶类
}

function teaStyles(tea) {
  // 如果是选中的茶类，返回对应的颜色
  if (activeTea.value === tea) {
    return {
      color: teaColors[tea],
      fontSize: '25px' // 选中时字体变大
    };
  }
  // 如果是鼠标悬停的茶类，返回悬停的样式
  if (hoverTea.value === tea) {
    return {
      color: teaColors[tea],
      fontSize: '25px' // 悬停时字体变大
    };
  }
  // 默认样式
  return {
    color: 'midnightblue',
    fontSize: '16px'
  };
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.allbox {
  display: flex;
  flex-direction: column;
  background-color: white;
  height: 100vh;
  width: 100%;
  max-width: 410px;
  margin: auto;
}

.top {
  display: flex;
  background-color: rgb(73, 236, 236);
  height: 100px;
  align-items: center;
  justify-content: center;
}

.Advertisement {
  height: 150px;
  background-color: darkgrey;
}

.flag {
  display: flex;
  height: 50px;
 background-color: #47bde7b3;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  align-items: baseline;
  font-size: larger;
}

.tea {
  cursor: pointer;
  transition: font-size 0.3s, color 0.3s;
}

.center {
  display: flex;
  flex-grow: 1;
}

.center2 {
  display: flex;
  flex-grow: 1;
}

.foot {
  display: flex;
  background-color: greenyellow;
  height: 50px;
  justify-content: space-around;
  align-items: center;
}

.fleft,
.fcenter,
.fcenter2,
.fright {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.fleft:hover,
.fcenter:hover,
.fcenter2:hover,
.fright:hover {
  box-shadow: inset 1px;
  background-color: aqua;
}

h1 {
  color: coral;
}
</style>